<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1987-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation.  A copy of
the license is included in the
section entitled "GNU Free Documentation License".

This manual contains no Invariant Sections.  The Front-Cover Texts are
(a) (see below), and the Back-Cover Texts are (b) (see below).

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Header Files (The C Preprocessor)</title>

<meta name="description" content="Header Files (The C Preprocessor)">
<meta name="keywords" content="Header Files (The C Preprocessor)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Index-of-Directives.html" rel="index" title="Index of Directives">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="index.html" rel="up" title="Top">
<link href="Macros.html" rel="next" title="Macros">
<link href="Overview.html" rel="prev" title="Overview">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
span:hover a.copiable-link {visibility: visible}
ul.mark-bullet {list-style-type: disc}
-->
</style>


</head>

<body lang="en">
<div class="chapter-level-extent" id="Header-Files">
<div class="nav-panel">
<p>
Next: <a href="Macros.html" accesskey="n" rel="next">Macros</a>, Previous: <a href="Overview.html" accesskey="p" rel="prev">Overview</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index-of-Directives.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h2 class="chapter" id="Header-Files-1"><span>2 Header Files<a class="copiable-link" href="#Header-Files-1"> &para;</a></span></h2>

<a class="index-entry-id" id="index-header-file"></a>
<p>A header file is a file containing C declarations and macro definitions
(see <a class="pxref" href="Macros.html">Macros</a>) to be shared between several source files.  You request
the use of a header file in your program by <em class="dfn">including</em> it, with the
C preprocessing directive &lsquo;<samp class="samp">#include</samp>&rsquo;.
</p>
<p>Header files serve two purposes.
</p>
<ul class="itemize mark-bullet">
<li><a class="index-entry-id" id="index-system-header-files"></a>
System header files declare the interfaces to parts of the operating
system.  You include them in your program to supply the definitions and
declarations you need to invoke system calls and libraries.

</li><li>Your own header files contain declarations for interfaces between the
source files of your program.  Each time you have a group of related
declarations and macro definitions all or most of which are needed in
several different source files, it is a good idea to create a header
file for them.
</li></ul>

<p>Including a header file produces the same results as copying the header
file into each source file that needs it.  Such copying would be
time-consuming and error-prone.  With a header file, the related
declarations appear in only one place.  If they need to be changed, they
can be changed in one place, and programs that include the header file
will automatically use the new version when next recompiled.  The header
file eliminates the labor of finding and changing all the copies as well
as the risk that a failure to find one copy will result in
inconsistencies within a program.
</p>
<p>In C, the usual convention is to give header files names that end with
<samp class="file">.h</samp>.  It is most portable to use only letters, digits, dashes, and
underscores in header file names, and at most one dot.
</p>

<ul class="mini-toc">
<li><a href="Include-Syntax.html" accesskey="1">Include Syntax</a></li>
<li><a href="Include-Operation.html" accesskey="2">Include Operation</a></li>
<li><a href="Search-Path.html" accesskey="3">Search Path</a></li>
<li><a href="Once_002dOnly-Headers.html" accesskey="4">Once-Only Headers</a></li>
<li><a href="Alternatives-to-Wrapper-_0023ifndef.html" accesskey="5">Alternatives to Wrapper #ifndef</a></li>
<li><a href="Computed-Includes.html" accesskey="6">Computed Includes</a></li>
<li><a href="Wrapper-Headers.html" accesskey="7">Wrapper Headers</a></li>
<li><a href="System-Headers.html" accesskey="8">System Headers</a></li>
</ul>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Macros.html">Macros</a>, Previous: <a href="Overview.html">Overview</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index-of-Directives.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
